package com.shop.service.impl;

import com.shop.mapper.IOrderMapper;
import com.shop.pojo.CommonResult;
import com.shop.pojo.OrderAssembly;
import com.shop.pojo.OrderVO;
import com.shop.service.IOrderService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class OrderServiceImpl implements IOrderService {
    @Resource
    private IOrderMapper orderMapper;

    @Override
    public CommonResult<OrderAssembly> getOrderList(String query, int pageNum, int pageSize) {
        int offset = (pageNum - 1) * pageSize;
        List<OrderVO> orderList = orderMapper.getOrderList(query, offset, pageSize);
        OrderAssembly orderAssembly = new OrderAssembly();
        orderAssembly.setPageNum(pageNum);
        orderAssembly.setTotal(orderMapper.getTotalOrders(query));
        orderAssembly.setOrderVO(orderList);
        return new CommonResult<>(200, "success", orderAssembly);
    }
}
